package com.axiang.lib_common.network;

import androidx.annotation.NonNull;

import com.axiang.lib_api.response.BaseResponse;
import com.axiang.lib_common.mvvm.model.BaseModel;
import com.axiang.lib_common.mvvm.viewmodel.BaseRefreshViewModel;
import com.axiang.lib_common.mvvm.viewmodel.BaseViewModel;
import com.axiang.lib_common.utils.NetUtil;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public abstract class RefreshObserver<T, VM extends BaseRefreshViewModel> extends CommonObserver<T, VM>{

    public RefreshObserver(VM vm) {
        super(vm);
    }

    @Override
    public void onSubscribe(@NonNull Disposable d) {
        if (!NetUtil.checkNetToast()){
            vm.postShowNetWorkErrViewEvent(true);
        }
    }

    @Override
    public void onComplete() {
        super.onComplete();

        vm.postStopRefreshEvent();
        vm.postStopLoadMoreEvent();
    }

    @Override
    public void onError(@NonNull Throwable e) {
        super.onError(e);

        vm.postStopRefreshEvent();
        vm.postStopLoadMoreEvent();
    }

}
